<!DOCTYPE html>
<html lang="en">

<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <meta charset="utf-8">
    <title></title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, user-scalable=no">
    <meta name="description" content="">
    <meta name="author" content="">
    <!-- STYLESHEETS -->
    <!--[if lt IE 9]>
    <script src="../../js/flot/excanvas.min.js"></script>
    <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
    <script src="http://css3-mediaqueries-js.googlecode.com/svn/trunk/css3-mediaqueries.js"></script><![endif]-->
    <link rel="stylesheet" type="text/css" href="../../css/cloud-admin.css">
    <link rel="stylesheet" type="text/css" href="../../css/themes/default.css" id="skin-switcher">
    <link rel="stylesheet" type="text/css" href="../../css/responsive.css">
    <link href="../../font-awesome/css/font-awesome.min.css" rel="stylesheet">
    <link rel="stylesheet" href="../../js/dropdown/dropdown.css">

    <!-- datatable -->
    <link rel="stylesheet" href="../../js/datatables/datatable.css">
    <link rel="stylesheet" href="../../js/datepicker/datepicker.css">
    <!-- SELECT2 -->
    <link rel="stylesheet" type="text/css" href="../../js/select2/select2.min.css"/>


</head>

<body>
<header class="navbar clearfix" id="header">
</header>

<!-- PAGE -->
<section id="page">
    <!-- SIDEBAR -->
    <div id="sidebar" class="sidebar">
        <div class="sidebar-menu nav-collapse">

            <!-- SIDEBAR MENU -->
            <ul>

            </ul>
            <!-- /SIDEBAR MENU -->
        </div>

    </div>
    <!-- /SIDEBAR -->
    <div id="main-content">
        <div class="modal fade" id="box-config" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog" style="margin-left: 200px;">
                <div class="modal-content" style="width:1000px">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                        <h4 class="modal-title">维护款式</h4>
                    </div>
                    <div class="modal-body">
                        <div class="row col-md-12">
                            <label class="control-label col-md-2" style="line-height:34px;"><span class="required">*</span>名称：</label>
                            <div class="col-md-3">
                                <input type="text" class="form-control" name="groupName" placeholder="请输入款式名称" maxlength="20">
                                <input type="hidden" name="id">

                            </div>
                        </div>

                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                        <button type="button" class="btn btn-success bt-save">保存</button>
                    </div>
                </div>
            </div>
        </div>
        <!-- pintuan-->
        <div class="modal fade" id="pintuan" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content" style="width:800px">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                        <h4 class="modal-title">拼团设置</h4>
                    </div>
                    <div class="modal-body">
                        <div class="form-group" style="margin-bottom:10px">
                            <label class="control-label col-md-2" style="line-height:34px;"><span class="required">*</span>拼团价格：</label>
                            <div class="col-md-3">
                                <input type="text" class="form-control" name="promotionPrice" placeholder="请输入拼团价格,0代表不拼团" maxlength="20"
                                       onkeypress="return $.IsDecimal(event);" onblur="return $.IsMoney(this);"/>
                                <input type="hidden" name="id"/>
                            </div>
                        </div>
                        <div class="form-group " style="margin-bottom:10px">
                            <label class="control-label col-md-2" style="line-height:34px;"><span class="required">*</span>拼团件数：</label>
                            <div class="col-md-3">
                                <input type="text" class="form-control" name="groupAmount" onkeypress="return $.IsNum(event);" onblur="return $.IsNaN(this);"
                                       placeholder="请输入拼团件数" maxlength="20"/>
                            </div>
                        </div>
                        <div class="form-group " style="margin-bottom:10px">
                            <label class="control-label col-md-2" style="line-height:34px;"><span class="required">*</span>成团时间：</label>
                            <div class="col-md-3">
                                <input type="text" class="form-control" name="groupDate" onkeypress="return $.IsNum(event);" onblur="return $.IsNaN(this);"
                                       placeholder="请输入成团时间" maxlength="20"/>
                            </div>
                        </div>
                        <div class="form-group " style="margin-bottom:10px">
                            <label class="control-label col-md-2" style="line-height:34px;"><span class="required">*</span>真实拼团：</label>
                            <div class="col-md-3">
                                <input type="checkbox" name="isReal">
                            </div>
                        </div>
                        <div class="form-group " style="margin-bottom:10px">
                            <label class="control-label col-md-2" style="line-height:34px;"><span class="required">*</span>拼团模式：</label>
                            <div class="col-md-4">
                                <select id="groupMode_select" name="groupMode">
                                    <option></option>
                                    <option value="Ordinary">普通拼团</option>
                                    <option value="OnlyNew">新客团</option>
                                    <option value="OldBeltNew">老带新</option>
                                </select>
                                <span class="error-span"></span>
                            </div>

                        </div>
                        <div class="form-group" style="margin-bottom:10px">
                            <label class="control-label col-md-2" style="line-height:34px;"><span class="required">*</span>分销价格：</label>
                            <div class="col-md-3">
                                <input type="text" class="form-control" name="distributionPrice" placeholder="分销价格" maxlength="20"
                                       onkeypress="return $.IsDecimal(event);" onblur="return $.IsMoney(this);"/>
                            </div>
                            <div class="required">取消拼团请重新设置分销价。</div>
                        </div>
                        <div class="form-group" id="vipRate_config">
                            <label class="control-label col-md-2" style="line-height:34px;"><span class="required">*</span>女王价比例：</label>
                            <div class="col-md-4">
                                <select id="vipRate_select" name="vipRate">
                                    <option></option>
                                    <option value="0.00">0%</option>
                                    <option value="0.05">5%</option>
                                    <option value="0.10">10%</option>
                                    <option value="0.15">15%</option>
                                    <option value="0.20">20%</option>
                                    <option value="0.25">25%</option>
                                    <option value="0.30">30%</option>
                                    <option value="0.35">35%</option>
                                </select>
                                <span class="error-span"></span>
                                <div class="required">取消拼团时必选。</br>设置拼团时无需考虑</div>
                            </div>
                        </div>
                        <!-- 			<div class="form-group " style="margin-bottom:10px">
                                <label class="control-label col-md-2" style="line-height:34px;"><span class="required">*</span>拼团返利：</label>
                                <div class="col-md-3">
                                    <select id="shareRate_select" name="shareRate">
                                        <option></option>
                                        <option value="0.03">3%</option>
                                        <option value="0.05">5%</option>
                                        <option value="0.1">10%</option>
                                      </select>
                                    <span class="error-span"></span>
                                </div>
                            </div>		 -->
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                        <button type="button" class="btn btn-success bt-save">保存</button>
                    </div>
                </div>
            </div>
        </div>
        <!-- /SAMPLE BOX CONFIGURATION MODAL FORM-->
        <div class="container">
            <div class="row">
                <div id="content" class="col-lg-12">
                    <!-- PAGE HEADER-->
                    <div class="row" style="height: 30px;">
                        <div class="col-sm-12">
                            <div class="page-header">
                                <!-- STYLER -->

                                <!-- /STYLER -->
                                <!-- BREADCRUMBS -->
                                <ul class="breadcrumb">
                                    <li>
                                        <i class="fa fa-home"></i>
                                        <a href="../index.html">首页</a>
                                    </li>
                                    <li>
                                        <a href="#">商品管理</a>
                                    </li>
                                    <li>商品款式</li>
                                </ul>
                                <!-- /BREADCRUMBS -->

                            </div>
                        </div>
                    </div>
                    <!-- /PAGE HEADER -->
                    <!-- FORMS QUERY-->
                    <div class="row">

                        <div class="box border primary">
                            <div class="box-title">
                                <h4><i class="fa fa-bars"></i>查询条件</h4>
                            </div>
                            <div class="box-body big" style="padding:10px;">

                                <div class="row mrg-bt10">
                                    <label class="col-sm-1 control-label" style="width: auto">款式名称：</label>
                                    <div class="col-sm-2">
                                        <input type="text" class="form-control" name="q" placeholder="输入关键字">
                                    </div>
                                    <div class="col-sm-2 tuan" style="width: 120px">
                                        <input type="checkbox" name="isGroup"><span style='margin-left:10px'>是否拼团</span>
                                    </div>
                                    <div class="col-sm-5">
                                        <a class="btn btn-primary search">查询</a>
                                        <a class="btn btn-success config create" style="margin-left:150px">
                                            <i class="fa  fa-plus-square-o"></i> 新增款式
                                        </a>
                                    </div>
                                </div>

                            </div>
                        </div>
                    </div>
                    <!-- /FORMS QUERY -->

                    <div class="row">
                        <!-- TABLES -->
                        <div class="col-md-12">
                            <!-- BOX -->
                            <div class="box border primary">
                                <div class="box-title">
                                    <h4><i class="fa fa-table"></i>款式数：<span id="total"></span>条 </h4>

                                </div>
                                <div class="box-body">
                                    <table id="db_group_list" cellpadding="0" cellspacing="0" border="0"
                                           class="datatable table table-striped table-bordered table-hover">

                                    </table>
                                </div>
                            </div>
                            <!-- /BOX -->
                        </div>
                    </div>
                    <!-- /TABLES -->

                </div>
                <!-- /CONTENT-->

            </div>
        </div>
        <input type="hidden" name="groupId"/>
</section>

<!--/PAGE -->
<!-- JAVASCRIPTS -->
<!-- Placed at the end of the document so the pages load faster -->
<!-- JQUERY -->
<script src="../../js/jquery/jquery-2.0.3.min.js"></script>
<!-- JQUERY UI-->
<script src="../../js/jquery-ui-1.10.3.custom/js/jquery-ui-1.10.3.custom.min.js"></script>
<!-- BOOTSTRAP -->
<script src="../../bootstrap-dist/js/bootstrap.min.js"></script>

<!-- BLOCK UI -->
<script type="text/javascript" src="../../js/jQuery-BlockUI/jquery.blockUI.min.js"></script>

<!-- AUTOSIZE -->
<script type="text/javascript" src="../../js/autosize/jquery.autosize.min.js"></script>

<!-- INPUT MASK -->
<script type="text/javascript" src="../../js/bootstrap-inputmask/bootstrap-inputmask.min.js"></script>

<!-- SELECT2 -->
<script type="text/javascript" src="../../js/select2/select2.min.js"></script>
<!-- UNIFORM -->
<script type="text/javascript" src="../../js/uniform/jquery.uniform.min.js"></script>


<!-- spinner -->
<script src="../../js/spinner/spin.js"></script>
<!-- DATA TABLES -->
<script type="text/javascript" src="../../js/datatables/bootstrap-select.js"></script>
<script type="text/javascript" src="../../js/datatables/datatable.js"></script>
<script type="text/javascript" src="../../js/datatables/datatable-bootstrap.js"></script>
<script type="text/javascript" src="../../js/datatables/datatable-tabletools.js"></script>
<script type="text/javascript" src="../../js/datatables/fnAddTr.js"></script>

<!--bootbox-->
<script type="text/javascript" src="../../js/bootbox/bootbox.min.js"></script>
<!-- COOKIE -->
<script type="text/javascript" src="../../js/jQuery-Cookie/jquery.cookie.min.js"></script>
<!-- CUSTOM SCRIPT -->
<script src="../../js/script.js"></script>
<script src="../../js/common.js"></script>
<script>
    var Group = function () {
        var $mainDataTable = null;
        var type = null;
        var saveGroup = function () {
            if ($("input[name=groupName]").val() == "") {
                $("#box-config").find(".form-group").addClass("has-error");
                return;
            } else {
                $.blockUI();
                var group = {};

                group.id = $("input[name=id]").val();
                group.groupName = $("input[name=groupName]").val();
                group.groupType = "Web";
                $.ajax({
                    type: "post",
                    url: App.getContextPath() + "admin/group/saveGroup.do",
                    async: true,
                    data: {
                        strGroup: JSON.stringify(group)
                    },
                    success: function (result) {
                        $.unblockUI();
                        if (result.type == "error") {
                            $.alert(result.extra);
                        } else {
                            $("#box-config").modal("hide");
                            searchGroup();
                        }
                    }
                });
            }
        };

        var delGroup = function () {
            var tr = $(this).closest("tr");
            var productNo = $(tr).find("td:eq(2) a").html();
            console.log(productNo);
            if (productNo !== '0') {
                $.alert("款式下已经绑定商品，请先解除关系后，再删除！");
                return;
            } else {
                $.confirm("确认删除此款式?", function () {
                    $.ajax({
                        type: "post",
                        url: App.getContextPath() + "admin/group/updateGroupStatus.do",
                        async: true,
                        data: {
                            id: $(tr).find("td:eq(0)").html()
                        },
                        success: function (result) {
                            searchGroup();
                        }
                    });
                });
            }
        };

        var searchGroup = function () {
            if (type == null) type = "Web";
            var groupType = type;
            var url = App.getContextPath() + "admin/group/searchGroup.do?q=" + $("input[name=q]").val() + "&groupType=" + $.cookie("groupType");
            url += "&isGroup=" + $("[name=isGroup]").prop("checked");
            var dtSetting = $.dataTableSetting({
                "ajaxSource": url,
                "serverSide": true,
                "bFilter": false, // 去掉搜索框
                "bLengthChange": false, // 每页显示数量

                "sScrollX": "100%",
                "sScrollXInner": "100%",
                "iDisplayLength": 25,

                "bSort": false,
                "aoColumns": [{
                    "mDataProp": "id",
                    "sTitle": "款式ID",
                    "width": "10%"
                }, {
                    "mDataProp": "groupName",
                    "sTitle": "款式名称",
                    "width": "20%"
                }, {
                    "mDataProp": "productNum",
                    "sTitle": "商品数",
                    "width": "10%",
                    "render": function (data, type, row) {
                        if (row.groupType == "Houtai")
                            return "<a  href='sku_list.html?groupId=" + row.id + "'>" + row.productNum + "</a>";
                        return "<a  href='#'>" + row.productNum + "</a>";
                    }
                }, {
                    "mDataProp": "promotionPrice",
                    "sTitle": "拼团价",
                    "width": "10%",
                    "class": groupType == "Houtai" ? "hide" : ""
                }, {
                    "mDataProp": "groupAmount",
                    "sTitle": "拼团件数",
                    "width": "10%",
                    "class": groupType == "Houtai" ? "hide" : ""
                }, {
                    "mDataProp": "groupDate",
                    "sTitle": "成团时间(小时)",
                    "width": "10%",
                    "class": groupType == "Houtai" ? "hide" : ""
                }, {
                    "mDataProp": "costPrice",
                    "sTitle": "总成本价",
                    "width": "8%",
                    "class": groupType == "Web" ? "hide" : ""
                }, {
                    "mDataProp": "basicAttribute",
                    "sTitle": "标签",
                    "class": groupType == "Web" ? "hide" : "basicAttribute"
                }, {
                    "mDataProp": "createTime",
                    "sTitle": "创建时间",
                    "width": "12%",
                    "render": function (data, type, row) {
                        return $.getLocalTime(row.createTime);
                    }
                }, {
                    "sTitle": "操作",

                    "render": function (data, type, row) {
                        var str = "<p class='btn-toolbar' style='margin:0px'>" +
                            "<button id=" + row.id + " class='btn btn-success btn-xs bt_edit btn-width'><i class='fa fa-pencil-square-o' style='margin-right:2px;'></i>编辑</button>" +
                            "<button class='btn btn-danger btn-xs bt_del btn-width'><i class='fa fa-trash-o'></i> 删除</button> ";

                        if (groupType == "Web") {
                            str += "<a  class='btn btn-primary btn-xs bt_add btn-width' style='margin-left:0px;margin-right:5px;margin-top:2px;width:80px;' href='add_product_recommend.html?groupId=" + row.id + "'><i class='fa fa-copy'></i>推荐商品</a>";
                            str += "<a  class='btn btn-warning btn-xs bt_addTuan btn-width' style='margin-left:0px;margin-right:5px;margin-top:2px;width:80px;'" +
                                "href='javascript:;' id=" + row.id + " promotionPrice=" + row.promotionPrice + " groupAmount=" + row.groupAmount +
                                " distributionPrice=" + row.distributionPrice + " shareRate=" + row.shareRate + " isReal=" + row.isReal + " groupMode=" + row.groupMode + " groupDate=" + row.groupDate + " ><i class='fa fa-plus-square-o'></i>拼团设置</a></p>";
                        }
                        return str;
                    }
                }, {
                    "mDataProp": "extMaterial",
                    "class": "extMaterial hide"
                }, {
                    "mDataProp": "categoryId",
                    "class": "categoryId hide"
                }]
            });

            $mainDataTable = $("#db_group_list").dataTable(dtSetting);
        }

        var fengkou = "",
            tiezhi = "",
            baozhuang = "",
            num = 1;


        var addTuan = function () {
            $("#shareRate_select").select2("val", "");
            var id = $(this).attr("id");
            var promotionPrice = $(this).attr("promotionPrice");
            var distributionPrice = $(this).attr("distributionPrice");
            var groupAmount = $(this).attr("groupAmount");
            // var shareRate = $(this).attr("shareRate");
            var groupDate = $(this).attr("groupDate");
            var groupMode = $(this).attr("groupMode");
            var isReal = $(this).attr("isReal");
            $("#pintuan").find("[name=id]").val(id);
            $("#pintuan").find("[name=promotionPrice]").val(promotionPrice);
            $("#pintuan").find("[name=groupDate]").val(groupDate);
            $("#pintuan").find("[name=distributionPrice]").val(distributionPrice);
            $("#pintuan").find("[name=isReal]").prop("checked", isReal == 'true' ? isReal : null);
            $("#pintuan").find("[name=groupAmount]").val(groupAmount == "null" ? "" : groupAmount);
            // $("#shareRate_select").select2("val",shareRate);
            $("#groupMode_select").select2("val", groupMode);
            $("#pintuan").modal("show");
            $("#pintuan").find(".bt-save").unbind("click").click(function () {
                $(".form-group").removeClass("has-error");
                promotionPrice = $("#pintuan").find("[name=promotionPrice]").val();
                groupAmount = $("#pintuan").find("[name=groupAmount]").val();
                distributionPrice = $("#pintuan").find("[name=distributionPrice]").val();
                groupDate = $("#pintuan").find("[name=groupDate]").val();
                //shareRate=$("#pintuan").find("[name=shareRate]").val();
                groupMode = $("#pintuan").find("[name=groupMode]").val();
                var vipRate = $("#pintuan").find("[name=vipRate]").val();
                if ((!promotionPrice || promotionPrice == 0) && (vipRate == null || vipRate == "")) {
                    $.alert("请选择女王价比例")
                    return;
                }

                isReal = $("[name=isReal]").prop("checked");
                /*  if(groupAmount == '' || groupAmount == 0){
                     $("#pintuan").find("[name=groupAmount]").parents(".form-group").addClass("has-error");
                     return false;
                 } */
                /* 	    if(shareRate == null || shareRate == ''){
                            $("#pintuan").find("[name=shareRate]").parents(".form-group").addClass("has-error");
                            return false;
                        } */
                $.confirm("确认修改拼团设置?", function () {
                    $.blockUI();
                    $.ajax({
                        type: "post",
                        url: App.getContextPath() + "admin/group/updateGroup.do",
                        async: true,
                        data: {
                            id: id,
                            groupAmount: groupAmount,
                            promotionPrice: promotionPrice,
                            //shareRate: shareRate,
                            isReal: isReal,
                            groupMode: groupMode,
                            vipRate: vipRate,
                            distributionPrice: distributionPrice,
                            groupDate: groupDate
                        },
                        success: function (result) {
                            $.unblockUI();
                            $("#pintuan").modal("hide");
                            searchGroup();
                        }
                    });
                });
            });
        }


        var tagsList = [],q=null;
        return {
            init: function () {
                type = $.getUrlParam("type");
                q=$.getUrlParam("q");
                if(q)$("[name=q]").val(q);
                $.cookie("groupType", type);
                searchGroup();
                $(".search").click(searchGroup);
                $(".bt-save").click(saveGroup);
                $(".create").click(function () {
                    if (type == "Houtai") {
                        window.location.href = "edit_group.html?flag=add";
                    } else {
                        $.clearInput();
                        $("#shareRate_select").select2({
                            placeholder: "选择分享返利"
                        });
                        $("#groupMode_select").select2({
                            placeholder: "选择拼团模式"
                        });


                        $("#box-config").find(".modal-content").css("width", "700px");
                        $("#box-config").find(".modal-body").css("height", "60px");


                        $("#box-config").modal("show");
                    }
                });
                $("#db_group_list").off("click").on("click", ".bt_edit", function () {
                    var tr = $(this).closest("tr");
                    $.clearInput();
                    $("#box-config").removeClass("has-error");
                    $("#box-config").find("input[name=id]").val($(tr).find("td:eq(0)").html());
                    $("#box-config").find("input[name=groupName]").val($(tr).find("td:eq(1)").html());
                    if (type == "Houtai") {
                        window.location.href = "edit_group.html?flag=edit&id=" + $(this).attr("id");
                    } else {
                        $("#shareRate_select").select2({
                            placeholder: "选择分享返利"
                        });
                        $("#groupMode_select").select2({
                            placeholder: "选择拼团模式"
                        });
                        $("#box-config").find(".modal-content").css("width", "700px");
                    }
                    $("#box-config").modal("show");
                });

                $("#db_group_list").on("click", ".bt_del", delGroup);
                $("#db_group_list").on("click", ".bt_addTuan", addTuan);
                if (type == "Houtai") $(".tuan").hide();
                $("#vipRate_select").select2({
                    placeholder: "选择女王价比例"
                });

            }

        }
    }();

    $(function () {
        $("#header").load("../head.html");
        App.init();
        Group.init();

    });
</script>
<!-- /JAVASCRIPTS -->
</body>

</html>